
const urlLib = require('url');

var obj = urlLib.parse('http://www.zyx58.com/index?a=12&b=5');

console.log(obj);

// Url {
//   protocol: 'http:',
//   slashes: true,
//   auth: null,
//   host: 'www.zyx58.com',
//   port: null,
//   hostname: 'www.zyx58.com',
//   hash: null,
//   search: '?a=12&b=5',
//   query: 'a=12&b=5',
//   pathname: '/index',
//   path: '/index?a=12&b=5',
//   href: 'http://www.zyx58.com/index?a=12&b=5'
// }

//=======传递第二个参数 true

var obj = urlLib.parse('http://www.zyx58.com/index?a=12&b=5',true);

console.log(obj);

Url {
  protocol: 'http:',
  slashes: true,
  auth: null,
  host: 'www.zyx58.com',
  port: null,
  hostname: 'www.zyx58.com',
  hash: null,
  search: '?a=12&b=5',
  query: { a: '12', b: '5' },
  pathname: '/index',
  path: '/index?a=12&b=5',
  href: 'http://www.zyx58.com/index?a=12&b=5'
}
